<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>AdminLTE 3 | Log in (v2)</title>

    <!-- Google Font: Source Sans Pro -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/plugins/fontawesome-free/css/all.min.css">
    <!-- icheck bootstrap -->
    <link rel="stylesheet" href="/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="/dist/css/adminlte.min.css">
</head>
<body class="hold-transition login-page">
<div class="login-box">
    <!-- /.login-logo -->
    <div class="card card-outline card-primary">
        <div class="card-header text-center">
            <a href="/index2.html" class="h3">学生成绩管理</a>
        </div>
        <div class="card-body">
            <p class="login-box-msg">看成绩，紧张吗？</p>

            <form action="#" name="frmLogin" id="frmLogin" method="post">
                <div class="input-group mb-3">
                    <input type="email" class="form-control" placeholder="学号"
                           id="txtName" name="txtName">
                    <div class="input-group-append">
                        <div class="input-group-text">
                            <span class="fas fa-envelope"></span>
                        </div>
                    </div>
                </div>
                <div class="input-group mb-3">
                    <input type="password" class="form-control" placeholder="密码"
                    id="txtPassword" name="txtPassword">
                    <div class="input-group-append">
                        <div class="input-group-text">
                            <span class="fas fa-lock"></span>
                        </div>
                    </div>
                </div>

            </form>

            <div class="social-auth-links text-center mt-2 mb-3">
                <a href="#" class="btn btn-block btn-primary" onclick="login()">
                    <i class="fab fa-facebook mr-2"></i> 登录
                </a>

            </div>
            <!-- /.social-auth-links -->


        </div>
        <!-- /.card-body -->
    </div>
    <!-- /.card -->
</div>
<!-- /.login-box -->

<!-- jQuery -->
<script src="/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="/dist/js/adminlte.min.js"></script>
<script>
    function login() {

        /*if(!$("#frmLogin").valid()){

            return false;
        }*/
        //1) 取用户名和密码

        var name = $("#txtName").val();
        var password = $("#txtPassword").val();


        //2) ajax 提交

        $.ajax({
            method: "POST",
            url: "/api/login/student",
            data: {
                "name":name,
                "password":password
            }
        })
            .done(function (result) {

                var code=result.code;
                var msg=result.msg;
                if (code!=null && code >= 0) {
                    //3)  如果成功，则转入到主页面
                    window.location.href="/student/list"

                } else {
                    alert("出错了！"+msg);
                }

            });


    }
</script>
</body>
</html>
